# encoding: utf-8

class CollectionsController < ApplicationController
  #  before_filter :login_required,:only=>[:new_interest,:create_interest,:new_rating,:create_rating]
  before_filter :find_item
  # 商品的打分

  #用户像买 买过了
  def new_interest
    @uii = User.first.user_item_interests.find_by_item_id(@item.id) || UserItemInterest.new
    render :partial => "new_interest"
  end

  def create_interest
    @uii = User.first.user_item_interests.find_by_item_id(@item.id) || User.first.user_item_interests.build(:item_id=>@item.id)
    flash[:notice] = "保存成功"
    redirect_to item_url(@item)
  end

  #评分
  def new_rating
    render :text => "评分"
  end

  def create_rating
    render :text => "评分"
  end

  protected

  def find_item
    @item = Item.find_by_id(params[:item_id])
    if @item.blank?
      redirect_to items_url
    end
  end

end
